#coding:utf-8
#image display module by winkidney littlekey |version 0.201
"""this is the background picture load and display module
include    method 
load()  to load the pic you need
show() show the pic you load
display_effect()  to display the pic by some effect"""

import pygame

import define

class IMG(object):
    #传入屏幕大小，surface对象的引用以便在函数内绘制自己
    def __init__(self,screen_size,surface):
        self.position = None
        self.screen_size = screen_size
        self.surface = surface
        self.image = None
        self.image_name = ""
    #装载文件并检测是否装载成功
    def load(self,image_filename,position="left_top"):
        self.position_char = position
        if self.image != None:
            self.image = None
        try:
            self.image = pygame.image.load(image_filename).convert_alpha()
        except IOError:
            print "bad filename or i/o error"+" "+image_filename
            return
        self.image_name = image_filename
    #显示文件。传入的参数为显示位置，几个显示位置分别适用于背景，立绘的中间，左边和右边，立绘从屏幕左边25px开始
    #将屏幕宽度减去50后分为三块作为左边，中间，右边
    def show(self,display_effect=0):
        temp_position_x = int((self.screen_size[1]-25)/3)
        temp_position_y = 150
        
        if self.position_char == "left":
            self.position = (25,temp_position_y)
        elif self.position_char == "right":
            self.position = (temp_position_x+25,temp_position_y)
        elif self.position_char == "center":
            self.position = (temp_position_x*2+25,temp_position_y)
        elif self.position_char == "left_top":
            self.position =(0,0)
        else:
            print "wrong position argument for"+self.image_name+"=。="
            return
        self.surface.blit(self.image,self.position)
            
    def display_effect(self):
        pass